package com.agua.enturno.vista.modelos;

import org.apache.wicket.model.IModel;
import org.joda.time.Duration;


public class MinutesInNumberModel implements IModel<Integer> {
	
	private static final long serialVersionUID = 1L;
	
	private IModel<Duration> minutesInDurationModel;
	
	public MinutesInNumberModel(IModel<Duration> minutesInDurationModel) {
		this.minutesInDurationModel = minutesInDurationModel;
	}

	@Override
	public void detach() {
		minutesInDurationModel.detach();
	}

	@Override
	public Integer getObject() {
		return minutesInDurationModel.getObject().toPeriod().getMinutes();
	}

	@Override
	public void setObject(Integer object) {
		this.minutesInDurationModel.setObject(this.minutesInDurationModel.getObject().toPeriod().withMinutes(object).toStandardDuration());
	}
	
}
